/**
 * @(#)ClientHeartBeat.java 2017年2月18日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.domian.channel;


import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

/**
 * 客户端心跳包
 * @author <a href="mailto:zhouchao@xingbook.com" >周超</a>
 * @version 1.0.0
 */
public class ClientHeartBeat implements Serializable{
	
	/**
	 * serialVersionUID TODO 请描述这个变量的含义
	 */
	private static final long serialVersionUID = -7217694816165225648L;

	public static final Logger LOGGER = LoggerFactory.getLogger(ClientHeartBeat.class);

	public static final int HEART=1;
	public static final int RUNNING=2;
	public static final int FINISH=3;
	public static final int FAILURE=4;
	public static final int REFUFE=5;
	
//	public static final int STOP_MARK=1;
//	public static final int START_MARK=0;
	
	/**
	 * 1、心跳   2、正在执行任务  3已完成任务 4 执行失败 5 拒绝执行任务
	 */
	private int actionType;
	/**
	 * 客户端IP(能否直接从request中获取)
	 */
	private String clientIp;
	private String clientMac;
	/**
	 * 母包版本
	 */
	private String version;
	/**
	 * 系统版本
	 */
	private String osVersion;
	/**
	 * 心跳包版本
	 */
	private String heartVersion;
	/**
	 * 0 正常  1表示休息中(暂停做任务)
	 */
	private int status;
	/**
	 * 设备ID
	 */
	private String uuid;
	
	private Long currentTime;
	
	private String taskId;
	
	private String msg;
	
	public int getActionType() {
		return actionType;
	}
	public void setActionType(int actionType) {
		this.actionType = actionType;
	}
	public String getClientIp() {
		return clientIp;
	}
	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getOsVersion() {
		return osVersion;
	}
	public void setOsVersion(String osVersion) {
		this.osVersion = osVersion;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}
	
	public Long getCurrentTime() {
		return currentTime;
	}
	public void setCurrentTime(Long currentTime) {
		this.currentTime = currentTime;
	}
	public String getTaskId() {
		return taskId;
	}
	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}
	
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public String getHeartVersion() {
		return heartVersion;
	}
	
	public void setHeartVersion(String heartVersion) {
		this.heartVersion = heartVersion;
	}
	
	public String getClientMac() {
		return clientMac;
	}
	public void setClientMac(String clientMac) {
		this.clientMac = clientMac;
	}
	
	@Override
	public int hashCode() {
		final int prime = 2017;
		int result = 1;
		result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null){
			return false;
		}
		if (this == obj){
			return true;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		
		ClientHeartBeat other = (ClientHeartBeat) obj;
		if (uuid == null) {
			if (other.uuid != null){
				return false;
			}
		} else if (!uuid.equals(other.uuid)){
			return false;
		}
		
		return true;
	}
	
	/**
	 * 
	 * 任务是否已经结束
	 * @author <a href="mailto:zhouchao@xingbook.com" >周超</a>
	 * @return
	 */
	public boolean hasStop(){
		if(this.actionType==FINISH||this.actionType==FAILURE||this.actionType==REFUFE){
			return true;
		}
		return false;
	}
	
	/**
	 * 
	 * 模拟器是否正在执行任务
	 * @author <a href="mailto:zhouchao@xingbook.com" >周超</a>
	 * @return
	 */
	public boolean hasBusy(){
		if(this.actionType==RUNNING){
			return true;
		}
		return false;
	}
	
	public void startWork(){
		this.actionType=RUNNING;
	}
	
	@Override
	public String toString(){
		return JSON.toJSONString(this);
	}
	
}
